<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>

<body>
    <ul>
        <li>知否知否，点我应有弹框在手！</li>
        <li>知否知否，点我应有弹框在手！</li>
        <li>知否知否，点我应有弹框在手！</li>
        <li>知否知否，点我应有弹框在手！</li>
        <li>知否知否，点我应有弹框在手！</li>
    </ul>
    <script>
        //事件委托，即利用事件的冒泡，仅给父级元素添加事件
        document.querySelector('ul').addEventListener('click', function(e) {
            // alert("事件委托")
            console.log(this.children.length)
            console.log(e.target)

            for (let i = 0; i < this.children.length; i++) {
                this.children[i].style.backgroundColor = "";
            }

            e.target.style.backgroundColor = 'pink';
        })
    </script>
</body>

</html>